package com.jzwl.xydk.manager.school.schoollabel.controller;

import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.jzwl.common.constant.Constants;
import com.jzwl.common.log.SystemLog;
import com.jzwl.common.page.PageObject;
import com.jzwl.common.upload.FileUploadUtils;
import com.jzwl.system.base.controller.BaseController;
import com.jzwl.xydk.manager.school.schoollabel.service.SchoolInfoService;

@Controller
@RequestMapping("/school")
public class SchoolInfoController extends BaseController{
	@Autowired
	private SystemLog systemLog;
	@Autowired
	private SchoolInfoService schoolInfoService;
	@Autowired
	private Constants constants;
	
	/**
	 * 学校列表
	 * 
	 */
	@RequestMapping(value = "/schoolList")
	public ModelAndView schoolList(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mov = new ModelAndView();
		PageObject po = new PageObject();
		createParameterMap(request);
		try{
			List cityList = schoolInfoService.cityList();
			po =  schoolInfoService.querySchoolList(paramsMap);
			mov.addObject("cityList",cityList);
			mov.addObject("po",po);
			mov.addObject("cityId",paramsMap.get("cityId"));
			mov.addObject("schoolName",paramsMap.get("schoolName"));
		}catch(Exception e){
			systemLog.errorLog(getClass(), "-", "-", "cityList", "学校列表", "查询学校列表失败！paramsMap：" + paramsMap, null);
			mov.addObject("msg", "查询学校列表异常！");
			mov.setViewName("/error");
			e.printStackTrace();
			return mov;
		}
		
		mov.setViewName("manager/schoolLabel/schoolList");
		 return mov;
		
	}
	
	@RequestMapping(value = "/toSchoolLabel")
	public String toSchoolLabel(HttpServletRequest request, HttpServletResponse response,Model model) {
		createParameterMap(request);
		try {
			List<Map<String, Object>> Labelist = schoolInfoService.toSchoolLabel(paramsMap);//查询所有标签
			List<Map<String, Object>> DicSkillist = schoolInfoService.querySkilDicdata(paramsMap);//查询字典资源中间表
			model.addAttribute("Labelist", Labelist);
			model.addAttribute("DicSkillist", DicSkillist);
			model.addAttribute("map",paramsMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "manager/schoolLabel/toEditLabel";
	}
	
	
	@RequestMapping(value = "/updateLabel")
	public String updateLabel(HttpServletRequest request, HttpServletResponse response,Model model) {
		createParameterMap(request);
		boolean flag=false;
		try {
			//List<Map<String, Object>> skilList = skillUserManagerService.queryExit(paramsMap);
			flag = schoolInfoService.updateLabel(paramsMap);//修改所属标签
			
			if(flag==true){
				
				Map<String,Object> map = schoolInfoService.getSchoolInfo(paramsMap.get("schoolId").toString());
				return "redirect:/school/schoolList.html?cityId="+map.get("cityId");
			}else{
				model.addAttribute("msg","保存失败");
				return "/error";
			}
		} catch (Exception e) {
			e.printStackTrace();
			model.addAttribute("msg","保存失败");
			return "/error";
			
		}
	}

}






























